package net.sf.rose.file.excel.poi.message;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.sf.rose.jdbc.bean.annotation.Column;
import net.sf.rose.jdbc.bean.annotation.Table;
import net.sf.rose.jdbc.bean.annotation.Type;

@Table(name = "SYS_EXCEL_MESSAGE", description = "Excel导入结果信息集")
public class SheetMessage {

    @Column(pk = true, name = "MESSAGE_ID", type = Type.定长文本, description = "编号", size = 32, policy = "UUID")
    private String messageID = null;

    /** 用户编号 */
    @Column(name = "USER_ID", type = Type.变长文本, description = "用户编号", size = 32)
    private String userID = null;

    @Column(name = "USER_NAME", type = Type.变长文本, description = "用户姓名", size = 50)
    private String userName = null;

    @Column(name = "TITLE", type = Type.变长文本, description = "标题说明", size = 100)
    private String title = null;

    @Column(name = "UPDATE_TIME", type = Type.日期时间, description = "操作时间")
    private Date updateTime = null;

    @Column(name = "TOTAL_COUNT", type = Type.数字整型, description = "总共行数")
    private int totalCount = 0;

    @Column(name = "SUCCESS_COUNT", type = Type.数字整型, description = "成功行数")
    private int successCount = 0;

    @Column(name = "ERROR_COUNT", type = Type.数字整型, description = "有错误行数")
    private int errorCount = 0;

    /** 有错误行信息 */
    private List<RowMessage> errorRowList = new ArrayList<>();

    public void addSuccessCount() {
        this.totalCount++;
        this.successCount++;
    }

    public void addErrorRowMessage(RowMessage message) {
        this.errorRowList.add(message);
        this.errorCount++;
        this.totalCount++;
    }

    public String getUserID() {
        return userID;
    }

    public void setUserID(String userID) {
        this.userID = userID;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getSuccessCount() {
        return successCount;
    }

    public void setSuccessCount(int successCount) {
        this.successCount = successCount;
    }

    public int getErrorCount() {
        return errorCount;
    }

    public void setErrorCount(int errorCount) {
        this.errorCount = errorCount;
    }

    public List<RowMessage> getErrorRowList() {
        return errorRowList;
    }

    public void setErrorRowList(List<RowMessage> errorRowList) {
        this.errorRowList = errorRowList;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append('\n');
        sb.append("total count:").append(totalCount).append('\n');
        sb.append("success count:").append(successCount).append('\n');
        sb.append("error count:").append(errorCount).append('\n');
        for (RowMessage message : errorRowList) {
            sb.append(message.toString()).append('\n');
        }
        return sb.toString();
    }

}
